export interface SuccessModuleParams {
    data: any;
    message?: string;
    [key: string]: any;
  }
  export class BasicModule {
    code: number;
    message: string;
    constructor(code: number, message: string) {
      this.code = code;
      this.message = message;
    }
  }
  
  class SuccessModule extends BasicModule {
    data: any;
    constructor(params: SuccessModuleParams) {
      let { data = null, message = "请求成功", ...restParams } = params;
      super(200, message);
      this.data = data;
      Object.keys(restParams).forEach((key: string) => {
        // @ts-ignore
        this[key] = restParams[key];
      });
    }
  }
  
  class ErrorModule extends BasicModule {
    data: null;
    constructor({ code = 500, message }: { code?: number; message: string }) {
      super(code, message);
      this.data = null;
    }
  }
  
  export { SuccessModule, ErrorModule };